package com.JZ.QM.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.JZ.QM.common.utils.PageUtils;
import com.JZ.QM.common.utils.Query;

import com.JZ.QM.common.dao.CombinationDynamicInfoDao;
import com.JZ.QM.common.entity.CombinationDynamicInfoEntity;
import com.JZ.QM.service.CombinationDynamicInfoService;

import javax.annotation.Resource;

/**
 *
 *
 * @author lyp
 * @email lyp@gmail.com
 * @date 2020-06-14 11:19:36
 */
@Service
public class CombinationDynamicInfoServiceImpl extends ServiceImpl<CombinationDynamicInfoDao, CombinationDynamicInfoEntity> implements CombinationDynamicInfoService {
    @Resource
    CombinationDynamicInfoDao combinationDynamicInfoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) throws Exception {
        IPage<CombinationDynamicInfoEntity> page = this.page(
                new Query<CombinationDynamicInfoEntity>().getPage(params),
                new QueryWrapper<CombinationDynamicInfoEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 根据组合基本id查询动态信息
     * @param comBaseId 组合动态信息的基本组合信息id
     * @return
     */
    @Override
    public CombinationDynamicInfoEntity getDynasticInfoByCombinationId(Long comBaseId) {
        //条件构造器
        QueryWrapper queryWrapper=new QueryWrapper();
        //组合的动态基本信息
        CombinationDynamicInfoEntity combinationDynamicInfoEntity=new CombinationDynamicInfoEntity();

        queryWrapper.eq("com_base_id",comBaseId);
        combinationDynamicInfoEntity=combinationDynamicInfoDao.selectOne(queryWrapper);
        return combinationDynamicInfoEntity;
    }

    /**
     * 更新组合的动态信息
     * @param comBaseId 组合id
     * @param collectNum 组合的收藏数量
     * @param visitNum 组合的参观数量
     * @param transactionNum 组合的额交易数量
     * @param purchaseNum 组合的购买数量
     * @return
     */
    @Override
    public Boolean updateComDynamic(Long comBaseId, Integer collectNum, Integer visitNum, Integer transactionNum, Integer purchaseNum) {
        //数据库组合动态信息匹配的行数
        Integer affectRow=0;
        affectRow=combinationDynamicInfoDao.updateComDynamicInfo(comBaseId,collectNum,visitNum,transactionNum,purchaseNum);
        if (affectRow >0){
            return true;
        } else {
            return false;
        }
    }

}